package com.yin97.kotiln.ui.activity

import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v4.app.FragmentPagerAdapter
import android.support.v7.app.AppCompatActivity
import android.view.MenuItem
import com.yin97.kotiln.R
import com.yin97.kotiln.ui.fragment.FragmentHolder
import com.yin97.kotiln.ui.fragment.Girl_Fragment
import com.yin97.kotiln.ui.fragment.android_Fragment
import com.yin97.kotiln.ui.fragment.ios_Fragment
import com.yin97.kotiln.ui.wight.BottomNavigationViewHelper
import kotlinx.android.synthetic.main.activity_home.*
import java.util.*




class HomeActivity : AppCompatActivity() {
        lateinit  var  fragments : MutableList<Fragment>
    var prevMenuItem: MenuItem? = null
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setSupportActionBar(tv_toobar)
        setContentView(R.layout.activity_home)
        initFragment()
        tv_toobar.setNavigationOnClickListener { finish() }
        tv_toobar.setTitle("大神带带我")
        BottomNavigationViewHelper.disableShiftMode(bottom_nv);
        viewpager.adapter =  object  :FragmentPagerAdapter(supportFragmentManager){
            override fun getCount()=  fragments.size
            override fun getItem(position: Int)=fragments[position]
        }
        viewpager.offscreenPageLimit=4
        bottom_nv.setOnNavigationItemSelectedListener { item ->
            var tab =0
            when (item.itemId){
            R.id.menu_android  -> tab = 0
                R.id.menu_ios -> tab = 1
                R.id.menu_girl -> tab = 2
                R.id.menu_about ->  tab= 3
            }
            viewpager.currentItem=tab
            false
        }
        floatingButton.setOnClickListener {  }
    }


    private  fun  initFragment(){
       var android : android_Fragment = android_Fragment()
        var  ios :ios_Fragment = ios_Fragment()
        val  girl : Girl_Fragment= Girl_Fragment()
        var  holder :FragmentHolder = FragmentHolder()
    fragments= ArrayList ()
        fragments.add(android)
        fragments.add(ios)
        fragments.add(girl)
        fragments.add(holder)
    }
}
